package com.hp.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hp.bean.Customer;
import com.hp.mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper mapper;
    @Override
    public PageInfo<Customer> selectfind(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Customer> list=mapper.selectfind();
        return new PageInfo<>(list);
    }

    @Override
    public int add(Customer customer) {
        return mapper.add(customer);
    }

    @Override
    public int upp(Customer customer) {
        return mapper.upp(customer);
    }

    @Override
    public Customer findById(Integer id) {
        return mapper.findById(id);
    }

    @Override
    public int del(Integer id) {
        return mapper.del(id);
    }

    @Override
    public List<Customer> login(String phone) {
        List<Customer> login = mapper.login(phone);
        if (login.size()>0){
            return (List<Customer>) login.get(0);
        }else {
            Customer customer = new Customer();
            customer.setPhone(phone);
            customer.setCreatetime(new Date());
            mapper.add(customer);
            return (List<Customer>) customer;
        }
    }

    @Override
    public int insert(Customer customer) {
        return mapper.insert(customer);
    }

    @Override
    public List<Customer> getList(Integer id) {
        return mapper.getList(id);
    }
}
